#define _CRT_SECURE_NO_WARNINGS 1

#include "AVLTree.h"
#include <ctime>
void TestAVLTree1()
{
	srand((size_t)time(nullptr));

	YX::AVLTree<int, int> tree;

	for (size_t i = 0; i < 10000; i++)
	{
		tree.Insert(make_pair(rand(), i));
		cout << "IsBalance:" << tree.IsBalance() << endl;
	}

}

void TestAVLTree2()
{
	YX::AVLTree<int, int> tree;

	int arr[] = { 25,33,7,111,234,67865,8768,2323,43434,57687,9,8,7,65,4,32 };

	for (auto e : arr)
	{
		tree.Insert(make_pair(e, e));
		cout << "IsBalance:" << tree.IsBalance() << endl;
	}
	cout << endl;
	tree.InOrder();

	for (auto e : arr)
	{
		tree.Erase(e);
		cout << "IsBalance:" << tree.IsBalance() << endl;
	}
	cout << endl;
}

void TestAVLTree3()
{
	YX::AVLTree<char, int> tree;

	string s = "abcdesadsfsf";

	for (auto e : s)
	{
		tree[e]++;
	}

	tree.InOrder();

}

void TestAVLTree4()
{
	YX::AVLTree<char, int> tree;

	string s = "abcdesadsfsf";

	for (auto e : s)
	{
		tree[e]++;
	}
	typename YX::AVLTree<char, int>::Iterator pos = tree.Find('a');
	
	if (pos != nullptr)
	{
		cout << pos->_kv.first << " : " << pos->_kv.second << endl;
	}
}

void TestAVLTree5()
{
	//srand((size_t)time(nullptr));

	YX::AVLTree<int, int> tree;

	for (size_t i = 0; i < 10000; i++)
	{
		tree.Insert(make_pair(rand(), i));
		//cout << "IsBalance:" << tree.IsBalance() << endl;
	}

	YX::AVLTree<int, int> copy(tree);

	int arr[] = { 25,33,7,111,234,67865,8768,2323,43434,57687,9,8,7,65,4,32 };

	for (auto e : arr)
	{
		copy.Insert(make_pair(e, e));
		cout << "IsBalance:" << copy.IsBalance() << endl;
	}

	copy = tree;
	copy.IsBalance();
}

void TestAVLTree6()
{

	YX::AVLTree<int, int> tree;

	for (size_t i = 0; i < 10000; i++)
	{
		tree.Insert(make_pair(rand(), i));
		//cout << "IsBalance:" << tree.IsBalance() << endl;
	}

	tree.InOrder();

	YX::AVLTree<int, int> copy;

	int arr[] = { 25,33,7,111,234,67865,8768,2323,43434,57687,9,8,7,65,4,32 };

	for (auto e : arr)
	{
		copy.Insert(make_pair(e, e));

		copy.Swap(tree);

		cout << "copy:" << copy.Height() <<"------" << "tree:" << tree.Height() << endl;

		cout << "IsBalance:" << copy.IsBalance() << endl;
	}

}

int main()
{

	TestAVLTree6();
	return 0;
}